package com.vcredit.creditcat.service;

import com.vcredit.creditcat.model.MerchantProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vcredit.creditcat.model.ChannelStatisticsExternal;
import com.vcredit.creditcat.persistence.base.ChannelStatisticsExternalMapper;

/**
 * 
 **/
@Service
public class ChannelStatisticsExternalService {
	@Autowired
	private ChannelStatisticsExternalMapper mapper;

	@Autowired
	private MerchantProductService merchantProductService;

	public void insert(ChannelStatisticsExternal obj) {
		if (obj.getProductId() <= 0 && null != obj.getChannelName()) {
			MerchantProduct product = merchantProductService.findByName(obj.getChannelName());
			if (null != product) {
				obj.setProductId(product.getProductId());
			}
		}
		mapper.insert(obj);
	}

	public void update(ChannelStatisticsExternal obj) {
		mapper.update(obj);
	}

	public void delete(String ids) {
		for (String feedbackIdString : ids.split(",")) {
			Long id = Long.parseLong(feedbackIdString);
			ChannelStatisticsExternal obj = new ChannelStatisticsExternal();
			obj.setIsDelete(1);
			obj.setChannelId(id);
			mapper.update(obj);
		}

	}

}